
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
int p[MAXN], q[MAXN], r[MAXN];
int n, m;

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i)
        p[i] = q[i] = r[i] = i;
    for (int _ = 1; _ <= m; ++_) {
        int op;
        scanf("%d", &op);
        if (op == 1) {
            int a, b;
            scanf("%d%d", &a, &b);
            p[a] = r[b];
        }
        else if (op == 2) {
            int a, b;
            scanf("%d%d", &a, &b);
            q[r[a]] = b;
            q[r[b]] = a;
            std::swap(r[a], r[b]);
        }
        else {
            int a;
            scanf("%d", &a);
            printf("%d\n", q[p[a]]);
        }
    }
    return 0;